// pages/start/select-player/select-player.js
const playerStores = require('../../../stores/players')
const computedBehavior = require("miniprogram-computed").behavior;

Component({
  behaviors: [computedBehavior],
  /**
   * 组件的初始数据
   */
  data: {
    players: [],
    selectPlayers: [],
  },

  computed: {
    hasPlayers(data) {
      return data.players?.length > 0;
    }
  },

  lifetimes: {
    attached() {
      const players = Object.values(playerStores.getPlayers());
      this.setData({ players });
    },
    
  },

  pageLifetimes: {
    show() {
      const players = Object.values(playerStores.getPlayers());
      this.setData({ players });
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleChoose(event) {
      const player = event.detail;
      this.triggerEvent('choose', player);
    },
    toPlayers() {
      wx.navigateTo({
        url: '/pages/players/players',
      })
    }
  }
})